<!DOCTYPE html>
<html lang="en">
<head>
    <title>Item - AIL</title>
    <link rel="icon" href="{{ url_for('static', filename='image/ail-icon.png') }}">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link href="{{ url_for('static', filename='css/bootstrap4.min.css') }}" rel="stylesheet">
    <link href="{{ url_for('static', filename='css/font-awesome.min.css') }}" rel="stylesheet">
    <link href="{{ url_for('static', filename='css/dataTables.bootstrap4.min.css') }}" rel="stylesheet">

    <script src="{{ url_for('static', filename='js/jquery.js')}}"></script>
    <script src="{{ url_for('static', filename='js/bootstrap4.min.js') }}"></script>
    <script src="{{ url_for('static', filename='js/jquery.dataTables.min.js') }}"></script>
    <script src="{{ url_for('static', filename='js/dataTables.bootstrap.min.js') }}"></script>

    <style>
        .scrollable-menu {
            height: auto;
            max-height: 200px;
            overflow-x: hidden;
            width:100%;
        }

		.red_table thead{
			background: #d91f2d;
			color: #fff;
		}
    </style>

</head>
<body>

  <div class="card mb-2">
    <div class="card-header bg-dark">
      <h3 class="text-white text-center" >{{ meta['id'] }}</h3>
    </div>
    <div class="card-body pb-1">
      <table class="table table-condensed table-responsive">
        <thead class="">
          <tr>
            <th>Date</th>
            <th>Source</th>
            <th>Encoding</th>
            <th>Size (Kb)</th>
            <th>Number of lines</th>
            <th>Max line length</th>
          </tr>
        </thead>
        <tbody>
          <tr>
          <td>{{ meta['date'] }}</td>
          <td>{{ meta['source'] }}</td>
          <td>{{ meta['mimetype'] }}</td>
          <td>{{ meta['size'] }}</td>
          <td>{{ meta['lines']['nb'] }}</td>
          <td>{{ meta['lines']['max_length'] }}</td>
          </tr>
        </tbody>
      </table>

      <div>
        <h5>
          {% for tag in meta['tags'] %}
            <span class="badge badge-{{ bootstrap_label[loop.index0 % 5] }}">{{ tag }}</span>
          {%  endfor %}
        </h5>
      </div>

    </div>
  </div>

  {% if meta['parent'] %}
    <div class="list-group" id="item_parent">
    parent: <a href="{{ url_for('objects_item.showItem')}}?id={{meta['parent']}}" target="_blank">{{meta['parent']}}</a>
    </div>
  {% endif %}

  {% if misp_eventid %}
    <div class="list-group" id="misp_event">
      <li class="list-group-item active">MISP Events already Created</li>
      <a target="_blank" href="{{ misp_url }}" class="list-group-item">{{ misp_url }}</a>
    </div>
  {% endif %}

  {% if hive_caseid %}
    <div class="list-group" id="misp_event">
      <li class="list-group-item active">The Hive Case already Created</li>
      <a target="_blank" href="{{ hive_url }}" class="list-group-item">{{ hive_url }}</a>
    </div>
  {% endif %}

  {% if  meta['duplicates'] != 0 %}
    <div id="accordionDuplicate" class="mb-2">
      <div class="card">
        <div class="card-header py-1" id="headingDuplicate">
          <div class="my-1">
            <i class="far fa-clone"></i> duplicates&nbsp;&nbsp;
            <div class="badge badge-warning">{{meta['duplicates']}}</div>
          </div>
        </div>
      </div>
    </div>
  {% endif %}


  {% if  meta['nb_correlations'] %}
    <div id="accordionCorrelation" class="mb-2">
      <div class="card">
        <div class="card-header py-1" id="headingCorrelation">
          <div class="my-1">
              <h5>
                  {% for obj_type in meta['nb_correlations'] %}
                      {% if meta['nb_correlations'][obj_type] %}
                          <span class="badge badge-dark">
                              {% if obj_type=='cve' %}
                                  <i class="fas fa-bug"></i>
                              {% elif obj_type=='cryptocurrency' %}
                                  <i class="fas fa-coins"></i>
                              {% elif obj_type=='decoded' %}
                                  <i class="fas fa-lock-open"></i>
                              {% elif obj_type=='pgp' %}
                                  <i class="fas fa-key"></i>
                              {% elif obj_type=='username' %}
                                  <i class="fas fa-user"></i>
                              {% elif obj_type=='screenshot' %}
                                  <i class="fas fa-image"></i>
                              {% else %}
                                  <i class="fas fa-cube"></i>
                              {% endif %}
                              {{ obj_type }}&nbsp;
                              <div class="badge badge-warning">{{meta['nb_correlations'][obj_type]}}</div>
                          </span>
                      {% endif %}
                  {% endfor %}
              </h5>
          </div>
        </div>
      </div>
    </div>
  {% endif %}

  {% if 'crawler' in meta %}
  <div id="accordionCrawler" class="mb-3">
    <div class="card">
      <div class="card-header py-1" id="headingCrawled">
        <div class="row">
          <div class="col-11">
            <div class="mt-2">
              <i class="fas fa-spider"></i> Crawled Item
            </div>
          </div>
          <div class="col-1">
            <button class="btn btn-link py-2 rotate" data-toggle="collapse" data-target="#collapseCrawled" aria-expanded="true" aria-controls="collapseCrawled">
              <i class="fas fa-chevron-circle-up"></i>
            </button>
          </div>
        </div>
      </div>

      <div id="collapseCrawled" class="collapse show" aria-labelledby="headingCrawled" data-parent="#accordionCrawler">
        <div class="card-body">

          <table class="table table-hover table-striped">
            <tbody>
              <tr>
                <td>Domain</td>
                <td><a target="_blank" href="{{ url_for('crawler_splash.showDomain') }}?domain={{ meta['crawler']['domain'] }}" id='domain'>{{ meta['crawler']['domain'] }}</a></td>
              </tr>
              <tr>
                <td>Father</td>
                <td><a target="_blank" href="{{ url_for('objects_item.showItem') }}?id={{ meta['parent'] }}" id='paste_father'>{{ meta['parent'] }}</a></td>
              </tr>
              <tr>
                <td>Url</td>
                <td>{{ meta['crawler']['url'] }}</td>
              </tr>
            </tbody>
          </table>

          <div class="card my-2" style="background-color:#ecf0f1;">
      			<div class="card-body py-2">
      				<div class="row">
      					<div class="col-md-8">
      						<input class="custom-range mt-2" id="blocks" type="range" min="1" max="50" value="13">
      					</div>
      					<div class="col-md-4">
      						<button class="btn btn-primary" onclick="blocks.value=50;pixelate();">
      							<i class="fas fa-search-plu"></i>
      						  <span class="label-icon">Full resolution</span>
      						</button>
      					</div>
      				</div>
      			</div>
      		</div>
      		<canvas id="canvas" style="width:100%;"></canvas>

        </div>
      </div>
    </div>
  </div>
  {% endif %}

  <div class="card bg-dark text-white">
    <div class="card-header">

      <div class="row">
        <div class="col-10">
          <h3> Content: </h3>
        </div>
        <div class="col-2">
          <div class="mt-2">
            <small><a class="text-info" href="{{ url_for('objects_item.item_raw_content') }}?id={{ request.args.get('paste') }}" id='raw_paste' > [Raw content] </a></small>
          </div>
        </div>
      </div>

    </div>
  </div>


  <p class="my-0" data-initsize="{{ initsize }}"> <pre id="paste-holder" class="border">{{ meta['content'] }}</pre></p>

  <script>
      var ltags
      var ltagsgalaxies
      $(document).ready(function(){
          $('#tableDup').DataTable();
          $('#tableb64').DataTable({
    				"aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "All"]],
    				"iDisplayLength": 5,
    				"order": [[ 1, "asc" ]]
    			});
          $(".rotate").click(function(){
        	 $(this).toggleClass("down")  ;
        	})
      });
  </script>

{% if 'crawler' in meta %}
  <script>
  var ctx = canvas.getContext('2d'), img = new Image();

  /// turn off image smoothing
  ctx.webkitImageSmoothingEnabled = false;
  ctx.imageSmoothingEnabled = false;

  img.onload = pixelate;
  img.addEventListener("error", img_error);
  var draw_img = false;

  img.src = "{{ url_for('objects_item.screenshot', filename=meta['crawler']['screenshot']) }}";

  function pixelate() {

    /// use slider value
    if( blocks.value == 50 ){
        size = 1;
    } else {
        var size = (blocks.value) * 0.01;
    }

    canvas.width = img.width;
    canvas.height = img.height;

    /// cache scaled width and height
    w = canvas.width * size;
    h = canvas.height * size;

    /// draw original image to the scaled size
    ctx.drawImage(img, 0, 0, w, h);

    /// pixelated
    ctx.drawImage(canvas, 0, 0, w, h, 0, 0, canvas.width, canvas.height);

  }

  function img_error() {
    img.onerror=null;
    img.src="{{ url_for('static', filename='image/AIL.png') }}";
    blocks.value = 50;
    pixelate;
  }

  blocks.addEventListener('change', pixelate, false);
  </script>
{% endif %}

  <div id="container-show-more" class="text-center">

  </div>

  </html>

</body>


</html>
